﻿using HoverTree.BLL;
using HoverTree.HoverTreeFrame;
using HoverTree.Model;
using System;
using System.Collections.Generic;
using System.Web.Services;

namespace HoverTreeWeb.HVTPanel.HPicture
{
    public partial class PictureList : System.Web.UI.Page
    {
        protected int _totalCount, _totalPageCount, _pageIndex, _pageSize;

        protected void btnGenerateAll_Click(object sender, EventArgs e)
        {
            if (txtHvtConfirm.Text == "hovertree")
            {
                if (ltlImageSetID.Text == string.Empty)
                {
                    txtHvtConfirm.Text = new HvtPicture().GenerateAll();
                    if (txtHvtConfirm.Text == "")
                        txtHvtConfirm.Text = "生成全部图片成功";
                }
                else
                    txtHvtConfirm.Text = new HvtPicture().GenerateAll(Convert.ToInt16(ltlImageSetID.Text));
                {

                    if (txtHvtConfirm.Text == "")
                        txtHvtConfirm.Text = "生成本图集全部图片成功";
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                _pageIndex = RequestHelper.GetQueryInt("pi", 1);
                _pageSize = 10;

                PictureSelect m_pictrueSelect = new PictureSelect();

                m_pictrueSelect.HvtImageSetId = RequestHelper.GetQueryInt("isid", -1);

                //获取图集信息
                ImageSetInfo m_isInfo = new ImageSetInfo();
                if (m_pictrueSelect.HvtImageSetId > 0)
                {                   
                    HvtImageSet m_bll = new HvtImageSet();
                    m_isInfo = m_bll.GetByID(m_pictrueSelect.HvtImageSetId);
                    if (m_isInfo == null)
                    {
                        ltlTips.Text = "图集不存在";
                        return;
                    }
                    ltlImageSetID.Text = m_isInfo.HvtID.ToString();
                    ltlImageSetTitle.Text = m_isInfo.HvtTitle;
                }

                List<PictureInfo> m_pictureList = new List<PictureInfo>();
                m_pictureList = new HvtPicture().HvtPageQuery(m_pictrueSelect, 3, _pageSize, _pageIndex, out _totalCount, out _totalPageCount);

                rptList.DataSource = m_pictureList;
                rptList.DataBind();

                string m_morePara = "isid=" + m_pictrueSelect.HvtImageSetId.ToString();
                ltlPages.Text = HoverTree.HoverTreeFrame.WebUI.KeleyiPager.BuildPageIndex(_pageIndex, _totalPageCount, m_morePara);

            }
        }

        [WebMethod]
        public static string SetCover(int hvtid)
        {
            if (hvtid < 1)
                return "ID错误";

            PictureSelect m_select = new PictureSelect();
            m_select.HvtId = hvtid;

            return new HvtPicture().SetCover(m_select);
        }

        [WebMethod]
        public static string HvtGenerate(int hvtid)
        {
            if (hvtid < 1)
                return "ID错误";

            PictureSelect m_select = new PictureSelect();
            m_select.HvtId = hvtid;

            HvtPicture m_bll = new HvtPicture();
            PictureInfo m_info = new PictureInfo();

            m_info = m_bll.Get(m_select);

            if (m_info == null)
                return "图片不存在";

            if (!m_info.HvtIsshow)
                return "图片为不公开显示。";

            return m_bll.Generate(m_info);
        }
    }
}